//
//  CellOfCollectionViewOfNew_discount.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/6.
//  Copyright © 2016年 KX. All rights reserved.
//
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "CellOfCollectionViewOfNew_discount.h"
@interface CellOfCollectionViewOfNew_discount ()
@property (nonatomic, strong) UIImageView *imageViewOfPhotot;
@property (nonatomic, strong) UILabel *labelOfPriceoff ;
@property (nonatomic, strong) UILabel *labelOfTitle;
@property (nonatomic, strong) UILabel *labelOfPrice;
@end
@implementation CellOfCollectionViewOfNew_discount
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageViewOfPhotot = [[UIImageView alloc]init];
        self.labelOfPrice = [[UILabel alloc]init];
        self.labelOfTitle = [[UILabel alloc]init];
        self.labelOfPriceoff = [[UILabel alloc]init];
        [self.contentView addSubview:self.imageViewOfPhotot];
        [self.contentView addSubview:self.labelOfPriceoff];
        [self.contentView addSubview:self.labelOfTitle];
        [self.contentView addSubview:self.labelOfPrice];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imageViewOfPhotot mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.equalTo(self.contentView);
        make.width.equalTo(self.contentView).multipliedBy(0.333);
    }];
    [self.labelOfTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfPhotot.mas_right).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(10);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_centerY);
    }];
    self.labelOfTitle.numberOfLines = 0;
    [self.labelOfPriceoff mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfPhotot.mas_right).mas_offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.height.mas_offset(10);
        self.labelOfPriceoff.textColor = [UIColor grayColor];
        self.labelOfPriceoff.font = [UIFont systemFontOfSize:12];
    }];
    [self.labelOfPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.height.mas_offset(12);
    }];
    self.labelOfPrice.textColor  = [UIColor redColor];
    
}
- (void)setModel:(ModelOfCountryNew_discount *)model{
    _model = model;
    NSRange range = NSMakeRange(4, model.price.length-11);
    NSString *str = [model.price substringWithRange:range];
    self.labelOfPrice.text = str;
    self.labelOfTitle.text = model.title;
    self.labelOfPriceoff.text = model.priceoff;
    [self.imageViewOfPhotot sd_setImageWithURL:[NSURL URLWithString:model.photo]];
}
@end
